<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button onclick="funA()">funA</button>
<button onclick="funB()">funB</button>
<button onclick="funC()">funC</button>
<button onclick="funD()">funD</button>
<button onclick="funE()">funE</button>
<button onclick="funF1()">funF1</button>
<button onclick="funF2()">funF2</button>
<button onclick="funF3()">funF3</button>
<button onclick="funF4()">funF4</button>
</body>
</html>
<script>
    function funA() {
        let attr1 = [2, 3, 5, 6, 8, 3];
        let attr2 = new Array(2, 3, 4, 5, 6, 7);
        console.log(attr1, attr2);
    }

    function funB() {
        let attr = [2, 3, 5, 6, 8, 3];
        attr[4] = 91;
        let a2 = attr[2]
        console.log(attr, a2);
    }

    function funC() {
        let attr = [2, 3, 5, 6, 8, 3];
        let len = attr.length
        console.log(len)
    }

    function funD() {
        let attr1 = [2, 3, 5, 6, 8, 3];
        let attr2 = [81, 35, 68];
        let attr3 = attr1.concat(attr2)
        let index1 = attr1.indexOf(5)
        let index2 = attr1.indexOf(12)
        attr2.sort(function (a, b) {
            return a - b
        })

        let attr4 = attr3.splice(2, 5)
        console.log(attr1, attr2, attr3);
        console.log(index1, index2);
        console.log(attr1.reverse());
        console.log(attr2);
        console.log(attr4);
        console.log(attr1.toString())
    }

    function funE() {
        let attr = [2, 3, 5, 6, 8, 3];
        console.log(attr);
        attr.push(12)
        console.log(attr);
        // 删除最后一个元素
        attr.pop()
        console.log(attr);
        // 删除第一个元素
        attr.shift()
        console.log(attr);
        // 删除指定位置的元素
        attr.splice(2, 1) // 第一个2代表起始位置，第二个2代表删除的个数
        console.log(attr);
    }

    function funF1() {
        let attr = [2, 3, 5, 6, 8, 3];
        for (let i = 0; i < attr.length; i++) {
            console.log(attr[i]);
        }
    }

    function funF2() {
        let attr = [2, 3, 5, 6, 8, 3];
        attr.forEach((e, i, atr) => {
            console.log(e, i, atr);
        })
    }

    function funF3() {
        let attr = [2, 3, 5, 6, 8, 3];
        attr.map((e, i, atr) => {
            console.log(e, i, atr);
        })
    }

    function funF4() {
        let attr = [2, 3, 5, 6, 8, 3];
        for (i in attr) {
            console.log(i);
        }
        console.log('----------------')
        for (e of attr) {
            console.log(e);
        }
    }
</script>